<?php
/**
 * Debug Logger SleekPHP Plug-in
 * Appends the logger table as well as run time
 * information to the <body>-element if DEBUG
 *
 * This could've been a module but I think it's better
 * as a "before_output"-plugin as they are run JUST before output
 * hence the run time information will be much more accurate
 *
 * @subpackage Plugins
 */
Events::bind('BeforeOutput', 'SPDebugLogger');

/**
 * Appends the Logger HTML table and
 * more to the <body>-element of $output
 *
 * @param string $output
 */
function SPDebugLogger ($output) {
	if (DEBUG) {
		# As a table
		$html = '<div id="debug-logger">' 
				. Logger::getLogsInConsole() # getLogsInConsole() || getLogsAsHTML()
				. '<p>' 
				. round(Logger::getRunTime(), 3) 
				. ' seconds, ' 
				. round(SleekPHP::db()->getNumQrys(), 3) 
				. ' database queries</p></div>';

		return str_replace('</body>', "$html</body>", $output);
	}

	return $output;
}
